<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设置 - 数独求解器</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen">
    <div class="container mx-auto px-4 py-8 max-w-3xl">
        <h1 class="text-4xl font-bold text-center text-gray-800 mb-10 pt-6">设置</h1>
        
        <div class="bg-white rounded-xl shadow-xl p-8 mb-8">
            <div class="mb-8">
                <div class="flex justify-between items-center">
                    <h2 class="text-2xl font-semibold text-gray-800 border-b-2 border-gray-200 pb-3">OCR引擎选择</h2>
                    <button id="back-btn" class="px-4 py-2 bg-gradient-to-r from-gray-600 to-slate-700 text-white rounded-lg hover:from-gray-700 hover:to-slate-800 transition-all shadow-md font-medium">返回</button>
                </div>
                <div class="space-y-5 mt-6">
                    <div class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition">
                        <input type="radio" id="tesseract" name="ocr-engine" value="tesseract" class="w-5 h-5 text-blue-600 mr-4" checked>
                        <label for="tesseract" class="text-xl font-medium text-gray-700">Tesseract.js <span class="text-gray-500 font-normal">(默认，离线识别)</span></label>
                    </div>
                    <div class="flex items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition">
                        <input type="radio" id="baidu" name="ocr-engine" value="baidu" class="w-5 h-5 text-blue-600 mr-4">
                        <label for="baidu" class="text-xl font-medium text-gray-700">百度OCR <span class="text-gray-500 font-normal">(在线识别，精度更高，需要解决跨域问题)</span></label>
                    </div>
                </div>
            </div>
            
            <div id="baidu-settings-container" class="hidden mb-10">
                <div id="baidu-settings-header" class="flex justify-between items-center cursor-pointer text-2xl font-semibold mb-6 text-gray-800 border-b-2 border-gray-200 pb-3">
                    <h2>百度OCR配置</h2>
                    <i id="toggle-icon" class="fas fa-chevron-down transition-transform duration-300"></i>
                </div>
                <div id="baidu-settings-content" class="hidden">
                    <div class="bg-amber-50 border-l-4 border-amber-500 p-5 mb-6 rounded-r-lg">
                        <p class="text-amber-700">
                            <strong>重要说明：</strong>百度OCR需要在本地服务器环境下运行才能正常工作，直接打开HTML文件会因浏览器安全策略限制而无法使用。
                        </p>
                    </div>
                    <div class="space-y-6">
                        <div>
                            <label for="api-key" class="block text-gray-700 text-lg mb-3">API Key</label>
                            <input type="password" id="api-key" class="w-full px-4 py-3 text-lg border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="请输入百度OCR API Key">
                        </div>
                        <div>
                            <label for="secret-key" class="block text-gray-700 text-lg mb-3">Secret Key</label>
                            <input type="password" id="secret-key" class="w-full px-4 py-3 text-lg border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="请输入百度OCR Secret Key">
                        </div>
                        <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded-r-lg">
                            <h3 class="font-semibold text-blue-800 mb-2">配置步骤：</h3>
                            <ol class="list-decimal list-inside text-blue-700 space-y-1">
                                <li>访问 <a href="https://ai.baidu.com/" target="_blank" class="text-blue-600 hover:underline">百度AI开放平台</a></li>
                                <li>注册账号并登录</li>
                                <li>创建应用，选择文字识别服务</li>
                                <li>获取API Key和Secret Key</li>
                                <li>将密钥填入上方输入框</li>
                                <li>点击"保存密钥"按钮</li>
                                <li>选择"百度OCR"作为默认OCR引擎</li>
                                <li>点击"保存设置"按钮</li>
                            </ol>
                            <div class="mt-3 p-3 bg-amber-100 rounded-lg">
                                <p class="text-amber-800 text-sm">
                                    <strong>重要提示：</strong>百度OCR由于浏览器安全策略限制可能无法直接使用。
                                    解决方案：
                                    <ol class="list-decimal list-inside mt-1 space-y-1">
                                        <li>使用本地服务器运行此应用（推荐）</li>
                                        <li>安装CORS解除阻止浏览器扩展</li>
                                        <li>使用Tesseract.js OCR引擎（默认，无跨域问题）</li>
                                    </ol>
                                </p>
                            </div>
                        </div>
                        <button id="save-keys" class="px-6 py-3 bg-gradient-to-r from-blue-500 to-sky-600 text-white text-lg rounded-lg hover:from-blue-600 hover:to-sky-700 transition-all shadow-md font-medium">保存密钥</button>
                    </div>
                </div>
            </div>
            
            <div id="statusMessage" class="status-message hidden mb-4 p-4 rounded-lg text-left"></div>
            
            <div class="flex justify-end pt-6">
                <button id="save-settings" class="px-6 py-3 bg-gradient-to-r from-green-500 to-emerald-600 text-white rounded-lg hover:from-green-600 hover:to-emerald-700 transition-all shadow-md font-medium">保存设置</button>
            </div>
        </div>
    </div>
    
    <script src="settings.js"></script>
</body>
</html>